//
//  UIImageView+LoadImage.m
//  ZYWebImage
//
//  Created by wangzhipan on 2025/3/5.
//

#import "UIImageView+LoadImage.h"
#import "UIView+WebCache.h"

@implementation UIImageView (LoadImage)
- (void)zy_setImageUrl:(NSString *)url
             placehold:(UIImage *)placehold
{
    [self zy_setImageUrl:url placehold:placehold completed:nil];
}


- (void)zy_setImageUrl:(NSString *)url
             placehold:(UIImage *)placehold
             completed:(void(^)(UIImage * _Nullable image, NSData  * _Nullable data))completed
{
    self.image = placehold;
    [self zy_externalSetImage:url completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, ZYImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
        if ([NSThread isMainThread]) {
            self.image = image;
        }
        else {
            dispatch_async(dispatch_get_main_queue(), ^{
                self.image = image;
            });
        }
        completed ? completed(image, data) : nil;
    }];
}

- (void)zy_cancelCurrentLoading
{
    [self zy_externalCancelCurrentLoading];
}
@end
